﻿
'Really a bad design
#If RETIRED Then
Imports xmlctrl
Imports xhtmlctrl
Imports webctrl
Imports wfileis.data
Imports avacom

Public Class idshow2
    Inherits container

    Public Const functionName As String = "idshow2"

    Private Shared Function context() As httpContext
        Return httpServer2.currentContext()
    End Function

    Private Shared Sub register(ByVal page As xhtmlpage)
        assert(Not page Is Nothing)
        assert(strsame(null.name(page.inlineScript()), "n"))
        Const begining As String = """+"
        Const ending As String = "+"""
        Const idph As String = "IDIDIDID"
        Dim idcardUrl As String = Nothing
        idcardUrl = urlgenerator.idcard(idph, targetUrl:=user.generateUserViewlink(idph))
        strrplc(idcardUrl, idph, begining + "i" + ending)
        If strendwith(idcardUrl, ending) Then
            idcardUrl = strleft(idcardUrl, strlen(idcardUrl) - strlen(ending))
            idcardUrl = """" + idcardUrl
        Else
            idcardUrl = """" + idcardUrl + """"
        End If
        page.inlineScript().addscript(functionName,
                                      "function " + functionName + "(i){" +
                                          "var f=function(t){if(t!=n)this.parentNode.innerHTML=t;};" +
                                          ajaxcall.invoke(page.inlineScript(),
                                                          idcardUrl,
                                                          callback:="f",
                                                          failedToGetResponse:="n") + ";}")
    End Sub

    Private Shared Function fetchAvatar(ByVal id As String) As String
        Return functionName + "(""" + htmlUtils.escape(id) + """)"
    End Function

    Public Sub setData(ByVal page As xhtmlpage, ByVal info As info, Optional ByVal prefix As String = Nothing)
        If info Is Nothing Then
            setData(page, convertor.cast(Of String)(Nothing), prefix)
        Else
            setData(page, info.id(), prefix)
        End If
    End Sub

    Public Sub setData(ByVal page As xhtmlpage, ByVal id As String, Optional ByVal prefix As String = Nothing)
        If Not page Is Nothing Then
            register(page)
        End If
        Dim idshow As idshow = Nothing
        idshow = context().createControl(New idshow())
        idshow.setData(id, prefix)
        addchild(idshow)
        Dim script As inlineScript = Nothing
        script = context().createControl(New inlineScript())
        script.addscript(network.http.contentType.textjavascript, functionName, fetchAvatar(id))
        addchild(script)
    End Sub
End Class
#End If
